FROM zxx99/alpine:edge
#
Maintainer Zxx99(1032869152@qq.com)

# Add basics first
RUN apk update && apk upgrade \
	&& apk add bash apache2 php7-apache2 curl ca-certificates openssl openssh git tzdata openntpd nano autoconf build-base linux-headers libaio-dev pcre-dev

# Add Composer
# RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer

# Setup apache and php
RUN apk add php7 \
	php7-dev \
	php7-opcache \
	php7-common  \
	php7-mysqlnd \
	php7-phar \
	php7-json \
	php7-iconv \
	php7-openssl \
	php7-ftp \
	php7-xdebug \
	php7-mcrypt \
	php7-mbstring \
	php7-soap \
	php7-gmp \
	php7-pdo \
	php7-pdo_odbc \
	php7-dom \
	php7-pdo \
	php7-zip \
	php7-mysqli \
	php7-sqlite3 \
	php7-pdo_pgsql \
	php7-bcmath \
	php7-gd \
	php7-odbc \
	php7-pdo_mysql \
	php7-pdo_sqlite \
	php7-gettext \
	php7-xmlreader \
	php7-xmlwriter \
	php7-simplexml \
	php7-tokenizer \
	php7-xmlrpc \
	php7-bz2 \
	php7-pdo_dblib \
	php7-curl \
	php7-ctype \
	php7-session \
	php7-redis \
	php7-sockets \
	php7-mongodb \
	&& cp /usr/bin/php7 /usr/bin/php \
    && rm -f /var/cache/apk/*

#安装swoole
RUN cd /root/ \
	#&& git clone https://github.com/swoole/swoole-src.git \
	&& git clone -b 1.9 https://git.oschina.net/swoole/swoole.git swoole-src \
	&& cd swoole-src/ \
	&& phpize \
	&& ./configure \
	&& make && make install \
	&& echo "extension=swoole.so" > /etc/php7/conf.d/99_swoole.ini \
	&& rm -rf /root/swoole-src/ \
	&& rm -rf /var/cache/apk/ \
	&& mkdir /var/cache/apk \
	&& rm -rf /tmp/*

# Add apache to run and configure
RUN mkdir /run/apache2 \
    && sed -i "s/#LoadModule\ rewrite_module/LoadModule\ rewrite_module/" /etc/apache2/httpd.conf \
    && sed -i "s/#LoadModule\ session_module/LoadModule\ session_module/" /etc/apache2/httpd.conf \
    && sed -i "s/#LoadModule\ session_cookie_module/LoadModule\ session_cookie_module/" /etc/apache2/httpd.conf \
    && sed -i "s/#LoadModule\ session_crypto_module/LoadModule\ session_crypto_module/" /etc/apache2/httpd.conf \
    && sed -i "s/#LoadModule\ deflate_module/LoadModule\ deflate_module/" /etc/apache2/httpd.conf \
    && sed -i "s#^DocumentRoot \".*#DocumentRoot \"/app/public\"#g" /etc/apache2/httpd.conf \
    && sed -i "s#/var/www/localhost/htdocs#/app/public#" /etc/apache2/httpd.conf \
    && printf "\n<Directory \"/app/public\">\n\tAllowOverride All\n</Directory>\n" >> /etc/apache2/httpd.conf

RUN mkdir /app && mkdir /app/public && chown -R apache:apache /app && chmod -R 755 /app && mkdir /bootstrap
ADD start.sh /bootstrap/
RUN chmod +x /bootstrap/start.sh

EXPOSE 80
ENTRYPOINT ["/bootstrap/start.sh"]